﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;



public partial class ViewAssignmentReport : System.Web.UI.Page
{
    public static int assId;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            assId = Convert.ToInt32(Request.QueryString["AssignmentId"]);
            if (assId != null)
                setControlValues();
        }

    }

    private void setControlValues()
    {
        int cntCompleted=0, cntPending=0;
        DataSet dsAssignment = new DataSet();
        dsAssignment = AdminCreateTestDAL.GetAssignInfoByAssignId(assId);
        lablAssignmentName.Text = dsAssignment.Tables[0].Rows[0][1].ToString();
        lablSubject.Text = dsAssignment.Tables[0].Rows[0][2].ToString();
        lablTopic.Text = dsAssignment.Tables[0].Rows[0][3].ToString();
        LablNoOfStudents.Text = dsAssignment.Tables[1].Rows.Count.ToString();
        for (int i = 0; i < dsAssignment.Tables[1].Rows.Count; i++)
        {
            if (dsAssignment.Tables[1].Rows[i][3].ToString().Trim() == "Submitted-Verified")
                cntCompleted++;
        }
        cntPending = dsAssignment.Tables[1].Rows.Count - cntCompleted;
        lablCompletedBy.Text=cntCompleted.ToString();
        lablPendingBy.Text=cntPending.ToString();

        bindGrid();
    }

    private void bindGrid()
    {
        DataTable dtAss = new DataTable();
        LinkButton link;
        dtAss = AdminCreateTestDAL.GetAssignmentTransAllInformation(assId);
        gvAssignment.DataSource = dtAss;
        gvAssignment.DataBind();

        for (int i = 0; i < dtAss.Rows.Count; i++)
        {
            for(int j=0;j<gvAssignment.Rows.Count;j++)
            {
                if(i==j)
                {
                    if(dtAss.Rows[i][4].ToString()=="")
                    {
                        link=((LinkButton)gvAssignment.Rows[j].FindControl("btnLink"));
                        link.Text="Not Submitted";
                        
                    }
                    else
                    {
                        link = ((LinkButton)gvAssignment.Rows[j].FindControl("btnLink"));
                        link.Text="View Assignment";
                    }
                }
            }
        }

        
    }
    protected void gvAssignment_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        object userId = e.CommandArgument;
        GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
        LinkButton lb = (LinkButton)row.FindControl("btnLink");
        if (lb.Text == "View Assignment")
        {
            switch (e.CommandName)
            {
                case "btnLinkClick": Response.Redirect("~/Admin/ViewStudentAssignmentByAdmin.aspx?AssignmentId=" + assId.ToString() + "&UserId=" + userId);
                    break;
            }
        }
    }
}